<?php

namespace yiike\company\model;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\company\model\TtycToker;

/**
* TtycTokerSearch represents the model behind the search form about `yiike\company\model\TtycToker`.
*/
class TtycTokerSearch extends TtycToker
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'uid',  'community_id', 'pid', 'ppid', 'company_id', 'type', 'level', 'status',  'updated_at', 'updated_by'], 'integer'],
            [['mobile', 'name', 'idcard', 'location_p', 'location_c', 'location_a', 'bank_name', 'bank_branch', 'bank_number', 'alipay', 'weixin'], 'safe'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TtycToker::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'uid' => $this->uid,
            'community_id' => $this->community_id,
            'pid' => $this->pid,
            'ppid' => $this->ppid,
            'company_id' => $this->company_id,
            'type' => $this->type,
            'level' => $this->level,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'updated_by' => $this->updated_by,
        ]);

        $query->andFilterWhere(['like', 'mobile', $this->mobile])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'idcard', $this->idcard])
            ->andFilterWhere(['like', 'location_p', $this->location_p])
            ->andFilterWhere(['like', 'location_c', $this->location_c])
            ->andFilterWhere(['like', 'location_a', $this->location_a])
            ->andFilterWhere(['like', 'bank_name', $this->bank_name])
            ->andFilterWhere(['like', 'bank_branch', $this->bank_branch])
            ->andFilterWhere(['like', 'bank_number', $this->bank_number])
            ->andFilterWhere(['like', 'alipay', $this->alipay])
            ->andFilterWhere(['like', 'weixin', $this->weixin]);

return $dataProvider;
}
}